const Mock = require("mockjs");
const getQuestionList = require("./data/getQuestionList");
const getComponent = require("./data/getComponent");
const { url } = require("koa-router");
const Random = Mock.Random;
module.exports = [
  //单个问卷信息
  {
    url: "/api/question/:id",
    response() {
      return {
        errno: 0,

        data: {
          id: Random.id(),
          title: Random.ctitle(),
          componentList: getComponent(),
          desc: "描述",
          css: "css",
          js: "js",
          isPublished: true,
        },
      };
    },
  },
  //创建问卷
  {
    url: "/api/question",
    method: "post",
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
          title: Random.ctitle(),
        },
      };
    },
  },
  {
    //问卷列表
    url: "/api/question",
    method: "get",
    response(ctx) {
      //   console.log(ctx);
      const { url, query = {} } = ctx;
      const isDeletd = url.indexOf("isDeleted=true") >= 0;
      const isStar = url.indexOf("isStar=true") >= 0;
      const pageSize = parseInt(query.pageSize) || 10;

      return {
        errno: 0,
        data: {
          list: [...getQuestionList({ len: pageSize, isDeletd, isStar })],
          total: 100,
        },
      };
    },
  },
  {
    //更新问卷
    url: "/api/question/:id",
    method: "patch",
    response(ctx) {
      return {
        errno: 0,
      };
    },
  },
  {
    //复制问卷
    url: "/api/question/duplicate/:id",
    method: "post",
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
        },
      };
    },
  },
  //批量删除
  {
    url: "/api/question",
    method: "delete",
    response() {
      return {
        errno: 0,
      };
    },
  },
];
